package com.lepu.app.fun.grow.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.app.utils.LoginUtil;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.utils.main.DateUtilBase;
import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.core.lib.widget.CircularImageView;
import com.eyzhs.app.R;
import com.lepu.app.fun.grow.bean.HotPhotoComment;

public class HotPhotoCommentAdapter extends BaseAdapter {

	private LayoutInflater mLayoutInflater = null;
	@SuppressWarnings("unused")
	private Context mContext = null;
	private ArrayList<HotPhotoComment> mArrayList = null;

	public HotPhotoCommentAdapter(Context context,
			ArrayList<HotPhotoComment> arrayList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mArrayList = arrayList;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (mArrayList != null && mArrayList.size() > 0) {
			size = mArrayList.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(
					R.layout.grow_hot_photo_comment_listitem, null);

			holder = new ViewHolder();

			CircularImageView accountIconImageView = (CircularImageView) convertView
					.findViewById(R.id.accountIconImageView);
			TextView titleTextView = (TextView) convertView
					.findViewById(R.id.titleTextView);
			TextView timeTextView = (TextView) convertView
					.findViewById(R.id.timeTextView);
			TextView bottomTitleTextView = (TextView) convertView
					.findViewById(R.id.bottomTitleTextView);

			holder.accountIconImageView = accountIconImageView;
			holder.titleTextView = titleTextView;
			holder.timeTextView = timeTextView;
			holder.bottomTitleTextView = bottomTitleTextView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final HotPhotoComment item = mArrayList.get(position);

//		holder.accountIconImageView.setImageBitmap(ImageUtilBase
//				.getBitmapByResId(mContext, R.drawable.default_icon_small));
//		if (!TextUtils.isEmpty(item.UserAvatar)) {
//			String fileName = EncodeMD5.getMd5(item.UserAvatar);
//			String filePath = SdLocal.getCacheImagePath(mContext, fileName);
//			String imageUrl = Setting.getImageUrl(item.UserAvatar);
//
//			BitmapManager.getInstance().loadBitmap(imageUrl, filePath,
//					holder.accountIconImageView, true);
//		}
		//UniversalImageLoadTool.disPlay(item.UserAvatar, holder.accountIconImageView, R.drawable.app_ic_default_avatar);
		LoginUtil.loadSelfUserImage(mContext, holder.accountIconImageView, item.UserAvatar);

		holder.accountIconImageView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LoginUtil.jumpUserInfo((BaseFragmentActivity) mContext, item.UserID);
			}
		});

		holder.titleTextView.setText(item.UserNickName);
		holder.timeTextView.setText(DateUtilBase
				.friendly_time(item.RecordCreateTime));
		holder.bottomTitleTextView.setText(item.ReplyContent);

		return convertView;
	}

	private static class ViewHolder {
		CircularImageView accountIconImageView;
		TextView titleTextView;
		TextView timeTextView;
		TextView bottomTitleTextView;
	}

}
